package demoworld.controllers;

import demoworld.business.interfaces.IBookBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import xxx.entities.result.BookResult;

/**
 * Created by francis on 2017/6/18.
 */

@Controller
@ResponseBody
@RequestMapping("/book")
public class BookController {
    //http://localhost:8080/book/?id=1 访问
    @Autowired
    private IBookBiz bookBiz;
    @RequestMapping("/")
    public BookResult getBookByBookId(@RequestParam(value = "id", required = false, defaultValue = "0") long id) {
        BookResult tmpResult =bookBiz.getBookByBookId(id);

        return tmpResult;
    }

//    //没有参数直接返回json
//    @RequestMapping("/")
//    public IndexResult hi1() {
//        IndexResult tmpResult = new IndexResult();
//        tmpResult.setId(System.currentTimeMillis());
//        tmpResult.setName("francis");
//        tmpResult.setPassword("oiweohjfwe0921348021");
//        return tmpResult;
//    }

//    //接收参数， 返回json
//    @RequestMapping("/2")
//    public IndexResult hi2(@RequestParam(value = "id", required = false, defaultValue = "0") long id) {
//        IndexResult tmpResult = new IndexResult();
//        tmpResult.setId(id > 0 ? id : System.currentTimeMillis());
//        tmpResult.setName("francis");
//        tmpResult.setPassword("oiweohjfwe0921348021");
//        return tmpResult;
//    }
//
//    //接收数组， 返回json
//    @RequestMapping("/3")
//    public IndexResult hi3(@RequestParam(value = "ids", required = true, defaultValue = "") long[] ids) {
//        IndexResult tmpResult = new IndexResult();
//        tmpResult.setId(ids != null && ids.length > 0 ? ids[0] : System.currentTimeMillis());
//        tmpResult.setName("francis");
//        tmpResult.setPassword("oiweohjfwe0921348021");
//        return tmpResult;
//    }
//
//    //接收参数对象， 返回json
//    @RequestMapping("/4")
//    public IndexResult hi4(@ModelAttribute("input") IndexResult input) {
//        if (input != null && input.getId()>0) {
//            return input;
//        }
//        IndexResult tmpResult = new IndexResult();
//        tmpResult.setId(System.currentTimeMillis());
//        tmpResult.setName("francis");
//        tmpResult.setPassword("oiweohjfwe0921348021");
//
//
//        return tmpResult;
//    }
}